# -*- coding: utf-8 -*-

import xlrd
import sqlite3

file_location = "IPC_Portugal_1977_2013.xls"

workbook = xlrd.open_workbook(file_location)

sheet = workbook.sheet_by_index(0)
print sheet.cell_value(0, 1)

print sheet.nrows

for col in range(sheet.ncols):
	print sheet.cell_value(0, col)
	
for col in range(sheet.ncols):
	print sheet.cell_value(2, col)
	
data = [[sheet.cell_value(r, c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]

print data[0][1]
print data[1][2]

conn = sqlite3.connect('IPC_Portugal_1977_2013.db')
c = conn.cursor()

c.execute('DROP TABLE IF EXISTS data')

c.execute('CREATE TABLE data (ano number, ipc_global number, var_anual number, rem_min_anual number, rem_max_anual number, pib_pc number, rnb_pc number, rdb_pc number, rem_pc number)')
conn.commit()

dados = [(2014, 0, 0, 0, 0, 0, 0, 0, 0), (2015, 0, 0, 0, 0, 0, 0, 0, 0)] 
c.executemany('INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', dados)
conn.commit()

c.execute('SELECT * FROM data')

conn.close()

